package com.ruoyi.common.utils;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

import java.io.IOException;

public class ApiSpaceSmsUtils {

    private static final String TOKEN = "49wcwjnsorm7ogqs05mna791g2999dlq";
    private static final String SMS_NOTIFY_URL = "https://eolink.o.apispace.com/sms-notify/notify";
    private static OkHttpClient client;

    static {
        client = new OkHttpClient().newBuilder().build();
    }

    public static void sendSmsNotify(String content) {
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, content);
        Request request = new Request.Builder()
                .url(SMS_NOTIFY_URL)
                .method("POST", body)
                .addHeader("X-APISpace-Token", TOKEN)
                .addHeader("Authorization-Type", "apikey")
                .addHeader("Content-Type", "application/json")
                .build();
        try {
            client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
